﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class users_user_recharge_success : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SysCommon.checkUserLogin();
        if (!IsPostBack)
        { 
            String moneyNum = Request["money_num"];
            String userId = Session["user_id"].ToString();
            if (moneyNum != null)
            {
                SqlTransaction myTrans = DataBaseOperate_SQLServer.objConnection.BeginTransaction();
                SqlCommand objCommand = new SqlCommand();
                objCommand.Connection = DataBaseOperate_SQLServer.objConnection;
                objCommand.Transaction = myTrans;
                try
                {
                    System.Text.StringBuilder sbstr = new System.Text.StringBuilder(200);

                    sbstr.Append("update t_user set balance = ((select balance from t_user where user_id = " + userId + ") + @moneyNum ) where  user_id = " + userId );                    
                    objCommand.CommandText = sbstr.ToString();
                    objCommand.Parameters.Add("@moneyNum", moneyNum);
                    //DataBaseOperate_SQLServer.ExecUpdate(objCommand);
                    objCommand.ExecuteNonQuery();
                    myTrans.Commit();                    
                }
                catch (Exception ex)
                {
                    Log.Record(ex);
                    myTrans.Rollback();
                }
                finally
                {
                    String sql = "select balance from t_user where user_id = " + userId;
                    DataRow dataRow = DataBaseOperate_SQLServer.GetDataRow(sql);
                    LabMessage.Text = "恭喜你支付成功！";
                    LabBalance.Text = dataRow["balance"].ToString();
                    LabRealPay.Text = moneyNum;
                }
            }
            else { 
                LabMessage.Text = "充值失败，请重试！";            
            }        
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("user_recharge_input.aspx");
    }
}
